<?php
ob_start();
session_start();
include "checksession.php";
date_default_timezone_set('Asia/Bangkok');
include("../connect.php");
$id_member = $_SESSION["id_member"];
$emp_id = $_GET['emp_id'];
$datetime = date("Y-m-d H:i:s");

$strSQL3 = "SELECT * FROM userlog WHERE id_member = '$id_member' ";
$objQuery3 = mysql_query($strSQL3);
$objResult3 = mysql_fetch_array($objQuery3);
$f_name = $objResult3["f_name"];
$l_name = $objResult3["l_name"];
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Adinop Co., Ltd. was founded as an ingredients importer and local manufacturers’ distributor in 1986. We also function as an exporter of finished products</title>
</head>
<body>
<?
	$strSQL = "UPDATE employee SET status = 'N' ";
	$strSQL .="WHERE emp_id = '".$_GET["emp_id"]."' ";
	$objQuery = mysql_query($strSQL);
	
	$strSQL4 = "UPDATE permissionfile SET status = 'N' ";
	$strSQL4 .="WHERE emp_id = '".$_GET["emp_id"]."' ";
	$objQuery4 = mysql_query($strSQL4);

	$strSQL2 = "SELECT * From employee INNER JOIN permissionfile ON employee.emp_id=permissionfile.emp_id where employee.emp_id = '".$_GET["emp_id"]."' ";
	$objQuery2 = mysql_query($strSQL2);
			
		require('fpdf.php');
		define('FPDF_FONTPATH','font/');

		//$test = $_GET['emp_id'];
		class PDF extends FPDF{

			function conv($string){
			return iconv('UTF-8', 'TIS-620', $string);
			}

			function Header(){

					$this->AddFont('angsa','','angsa.php');
					$this->AddFont('angsana','B','angsab.php');
					$this->SetFont('angsana','B',10);
					$this->SetFont('angsa','',14);
					$this->Text(10,10,iconv( 'UTF-8','TIS-620',"No. 13-U................" ),0,1,"L");
					$this->Text(38,10,iconv( 'UTF-8','TIS-620',"Date/Time................................."),0,1,"L");
					$this->Text(81,10,iconv( 'UTF-8','TIS-620',"Computer ID : ........................................."),0,1,"L");
					$this->AddFont('tahoma','','tahoma.php');
					$this->SetFont('tahoma','',9);
					$this->Text(180,8,iconv( 'UTF-8','TIS-620',"F-IT-009 R00"),0,1,"R");
					$this->Ln(2);
				}
			
			function Footer(){
				
				$this->SetY(-0.05);
				}
		}
		$pdf=new PDF();
		//*** Load MySQL Data ***//
		include "../connect.php";
		$strSQL = "SELECT * FROM employee INNER JOIN mail ON employee.emp_id = mail.emp_id INNER JOIN depart ON depart.id = employee.de_id LEFT JOIN comname ON comname.cn_id = employee.cn_id where employee.emp_id ='$emp_id' order  by emp_startDate DESC";
		$objQuery = mysql_query($strSQL);
		mysql_query("set NAMES'TIS620'");
		$resultData = array();
		for ($i=0;$i<mysql_num_rows($objQuery);$i++) {
			$result = mysql_fetch_array($objQuery);
			array_push($resultData,$result);
			
			if($result["mail_coth"] == ""){
				$result["mail_coth"]= xxxx;
			}
			if($result['emp_createDate'] == "0000-00-00 00:00:00"){
				$result['emp_createDate'] = "";
			}
			if($result['mail_authorizedDate'] == "0000-00-00 00:00:00"){
				$result['mail_authorizedDate'] = "";
			}
			if($result['mail_requestUserDate'] == "0000-00-00 00:00:00"){
				$result['mail_requestUserDate'] = "";
			}
			if($result['mail_staffITdate'] == "0000-00-00 00:00:00"){
				$result['mail_staffITdate'] = "";
			}
			if($result['mail_authorizedConDate'] == "0000-00-00 00:00:00"){
				$result['mail_authorizedConDate'] = "";
			}
			if($result['mail_supervisorDate'] == "0000-00-00 00:00:00"){
				$result['mail_supervisorDate'] = "";
			}
		}

		$cn_number = $result['cn_number'];
		if($cn_number == null){
			$cn_number = "";
		}else{
		$strSQL2 = "SELECT * FROM product_detail where pd_id = $cn_number";
		$objQuery2 = mysql_query($strSQL2);
		$result2 = mysql_fetch_array($objQuery2);
		mysql_query("set NAMES'TIS620'");
		}

		//************************//
		$pdf->AddPage('P','A4');
		$pdf->SetAutoPageBreak(true , 5);
		$pdf->AddFont('browallia','','browa.php');
		$pdf->AddFont('browallia','B','browab.php');
		$pdf->AddFont('browallia','I','browai.php');
		$pdf->AddFont('browallia','BI','browaz.php');
		$pdf->SetFont('browallia','B',15);
		$pdf->SetFillColor(194,194,194);

		$pdf->Cell(190,7,iconv('UTF-8','TIS-620','ใบทะเบียนประวัติเจ้าหน้าที่'),1,1,'C',true);
		
		$pdf->Cell(25,7,iconv( 'UTF-8','TIS-620',"ADD"),0,0,"C");
		$pdf->Cell(25,7,iconv( 'UTF-8','TIS-620',"EDIT"),0,0,"C");
		$pdf->Cell(25,7,iconv( 'UTF-8','TIS-620',"CANCEL"),0,1,"C");
		$pdf->Image('../images/true.jpg',11,20,5);

		$pdf->AddFont('browallia','','browa.php');
		$pdf->Cell(37,7,iconv('UTF-8','TIS-620','Employee ID : '),1,0,'R');
		$pdf->Cell(55,7,iconv('UTF-8','TIS-620',''.$_GET['emp_id']),1,0,'C');
		$pdf->Cell(6,7,iconv('UTF-8','TIS-620',''),0,0,'R');
		$pdf->Cell(37,7,iconv('UTF-8','TIS-620','Department : '),1,0,'R');
		$pdf->Cell(55,7,iconv('UTF-8','TIS-620',''.$result['departname']),1,1,'C');

		$pdf->Cell(37,7,iconv('UTF-8','TIS-620','Name (ENG) : '),1,0,'R');
		$pdf->Cell(55,7,iconv('UTF-8','TIS-620',''.$result['emp_nameEng']),1,0,'C');
		$pdf->Cell(6,7,iconv('UTF-8','TIS-620',''),0,0,'R');
		$pdf->Cell(37,7,iconv('UTF-8','TIS-620','Name (TH) : '),1,0,'R');
		$pdf->Cell(55,7,iconv('UTF-8','TIS-620',''.$result['emp_nameTh']),1,1,'C');

		$pdf->Cell(37,7,iconv('UTF-8','TIS-620','Surname (ENG) : '),1,0,'R');
		$pdf->Cell(55,7,iconv('UTF-8','TIS-620',''.$result['emp_surnameEng']),1,0,'C');
		$pdf->Cell(6,7,iconv('UTF-8','TIS-620',''),0,0,'R');
		$pdf->Cell(37,7,iconv('UTF-8','TIS-620','Surname (TH) : '),1,0,'R');
		$pdf->Cell(55,7,iconv('UTF-8','TIS-620',''.$result['emp_surnameTh']),1,1,'C');

		$pdf->Cell(37,7,iconv('UTF-8','TIS-620','Strat Date : '),1,0,'R');
		$pdf->Cell(55,7,iconv('UTF-8','TIS-620',''.$result['emp_startDate']),1,1,'C');

		$pdf->Ln(3);

		$pdf->Cell(37,7,iconv('UTF-8','TIS-620','Username : '),1,0,'R');
		$pdf->Cell(55,7,iconv('UTF-8','TIS-620',''.$result['mail_username']),1,0,'C');
		$pdf->Cell(6,7,iconv('UTF-8','TIS-620',''),0,0,'R');
		$pdf->Cell(37,7,iconv('UTF-8','TIS-620','By Request : '),1,0,'R');
		$pdf->Cell(55,7,iconv('UTF-8','TIS-620',''.$result['mail_request']),1,1,'C');

		$pdf->Cell(55,7,iconv('UTF-8','TIS-620',''.$result['mail_local']),1,0,'C');
		$pdf->Cell(37,7,iconv('UTF-8','TIS-620','@admail.local'),1,0,'L');
		$pdf->Cell(6,7,iconv('UTF-8','TIS-620',''),0,0,'R');
		$pdf->Cell(37,7,iconv('UTF-8','TIS-620','Date/Time : '),1,0,'R');
		$pdf->Cell(55,7,iconv('UTF-8','TIS-620',''.$result['mail_requestDate']),1,1,'C');

		$pdf->Cell(55,7,iconv('UTF-8','TIS-620',''.$result['mail_coth']),1,0,'C');
		$pdf->Cell(37,7,iconv('UTF-8','TIS-620','@adinop.co.th'),1,0,'L');
		$pdf->Cell(6,7,iconv('UTF-8','TIS-620',''),0,0,'R');
		$pdf->Cell(37,7,iconv('UTF-8','TIS-620','By Authorized : '),1,0,'R');
		$pdf->Cell(55,7,iconv('UTF-8','TIS-620',''.$result['mail_authorized']),1,1,'C');

		$pdf->Cell(37,7,iconv('UTF-8','TIS-620','Remark : '),1,0,'R');
		$pdf->Cell(55,7,iconv('UTF-8','TIS-620',''.$result['mail_remark']),1,0,'C');
		$pdf->Cell(6,7,iconv('UTF-8','TIS-620',''),0,0,'R');
		$pdf->Cell(37,7,iconv('UTF-8','TIS-620','Date/Time : '),1,0,'R');
		$pdf->Cell(55,7,iconv('UTF-8','TIS-620',''.$result['mail_authorizedDate']),1,1,'C');

		$pdf->Ln(3);

		$pdf->SetFillColor(0,0,0);
		$pdf->Cell(92,0.5,iconv('UTF-8','TIS-620',''),1,0,'C',true);
		$pdf->Cell(6,7,iconv('UTF-8','TIS-620',''),0,0,'R');
		$pdf->Cell(92,0.5,iconv('UTF-8','TIS-620',''),1,1,'C',true);

		$pdf->Ln(1);

		$pdf->SetFillColor(194,194,194);
		$pdf->Cell(92,7,iconv('UTF-8','TIS-620','For User Verify'),1,0,'C',true);
		$pdf->Cell(6,7,iconv('UTF-8','TIS-620',''),0,0,'R');
		$pdf->Cell(92,7,iconv('UTF-8','TIS-620','For IT Staff'),1,1,'C',true);

		$pdf->Cell(37,7,iconv('UTF-8','TIS-620','By Request : '),1,0,'R');
		$pdf->Cell(55,7,iconv('UTF-8','TIS-620',''.$result['mail_requestUser']),1,0,'C');
		$pdf->Cell(6,7,iconv('UTF-8','TIS-620',''),0,0,'R');
		$pdf->Cell(37,7,iconv('UTF-8','TIS-620','By Staff : '),1,0,'R');
		$pdf->Cell(55,7,iconv('UTF-8','TIS-620',''.""),1,1,'C');

		$pdf->Cell(37,7,iconv('UTF-8','TIS-620','Date/Time : '),1,0,'R');
		$pdf->Cell(55,7,iconv('UTF-8','TIS-620',''.$result['mail_requestUserDate']),1,0,'C');
		$pdf->Cell(6,7,iconv('UTF-8','TIS-620',''),0,0,'R');
		$pdf->Cell(37,7,iconv('UTF-8','TIS-620','Date/Time : '),1,0,'R');
		$pdf->Cell(55,7,iconv('UTF-8','TIS-620',''),1,1,'C');

		$pdf->Ln(3);

		$pdf->SetFont('browallia','BU',15);
		$pdf->Cell(190,7,iconv('UTF-8','TIS-620','Request Fulfillments'),1,1,'C',true);
		$pdf->SetFont('browallia','B',15);

		$pdf->Cell(37,7,iconv('UTF-8','TIS-620','By Authorized : '),1,0,'R');
		$pdf->Cell(55,7,iconv('UTF-8','TIS-620',''.$result['mail_authorizedCon']),1,0,'C');
		$pdf->Cell(6,7,iconv('UTF-8','TIS-620',''),0,0,'R');
		$pdf->Cell(37,7,iconv('UTF-8','TIS-620','By Supervisor : '),1,0,'R');
		$pdf->Cell(55,7,iconv('UTF-8','TIS-620',''.""),1,1,'C');

		$pdf->Cell(37,7,iconv('UTF-8','TIS-620','Date/Time : '),1,0,'R');
		$pdf->Cell(55,7,iconv('UTF-8','TIS-620',''.$result['mail_authorizedConDate']),1,0,'C');
		$pdf->Cell(6,7,iconv('UTF-8','TIS-620',''),0,0,'R');
		$pdf->Cell(37,7,iconv('UTF-8','TIS-620','Date/Time : '),1,0,'R');
		$pdf->Cell(55,7,iconv('UTF-8','TIS-620',''),1,1,'C');

		$pdf->SetFont('browallia','',12);
		$pdf->Text(24,9.5,iconv("UTF-8", "ISO-8859-11","".$result['emp_no13u']),0,1,"C");
		$pdf->Text(53,9.5,iconv("UTF-8", "ISO-8859-11","".$result['emp_createDate']),0,1,"C");
		$pdf->Text(102,9.5,iconv("UTF-8", "ISO-8859-11","".$result2['pd_name']),0,1,"C");

		$pdfs="../Bill_Cancel_F-IT-009/"."F-IT-009-".$emp_id.".pdf"; 
		$pdf->Output($pdfs,"F");
		//$pdf->Output();
		
		

		
	class PDF2 extends FPDF{

		function conv($string){
	return iconv('UTF-8', 'TIS-620', $string);
	}

	function Header(){
			
			$this->SetLeftMargin( 20 );
			$this->AddFont('angsa','','angsa.php');
			$this->AddFont('angsana','B','angsab.php');
			$this->SetFont('angsana','B',10);
			$this->SetFont('angsa','',14);
			$this->AddFont('tahoma','','tahoma.php');
	 		$this->SetFont('tahoma','',10);
			$this->Text(20,15,iconv( 'UTF-8','TIS-620',"No. 13-S................" ),0,1,"L");
			$this->Text(55,15,iconv( 'UTF-8','TIS-620',"Date/Time..................................."),0,1,"L");
			$this->SetFont('tahoma','',9);
			$this->Text(267,12,iconv( 'UTF-8','TIS-620',"F-IT-004 R05"),0,1,"R");
			$this->Ln(8);

			$this->AddFont('browallia','','browa.php');
			$this->AddFont('browallia','B','browab.php');
			$this->AddFont('browallia','I','browai.php');
			$this->AddFont('browallia','BI','browaz.php');
			$this->SetFont('browallia','B',16);
			$this->SetFillColor(194,194,194);

			$this->Cell(267,8,iconv('UTF-8','TIS-620','ใบทะเบียนประวัติสิทธิ์การเข้าถึงข้อมูล'),1,1,'C',true);
			$this->Ln(7);
			$this->Text(30,34,iconv( 'UTF-8','TIS-620',"ADD"),0,1,"C");
			$this->Text(52,34,iconv( 'UTF-8','TIS-620',"CANCEL ALL"),0,1,"C");
			$this->Text(230,34,iconv( 'UTF-8','TIS-620',"Reference:"),0,1,"C");
			$this->Image('../images/true.jpg',23,29,5);
			
			$this->Text(73,14.5,iconv( 'UTF-8','TIS-620',''.$_GET['date']),0,1,"C");
			$this->Text(35,14.5,iconv( 'UTF-8','TIS-620',''.$_GET['no13']),0,1,"C");
			$this->Text(252,34,iconv( 'UTF-8','TIS-620','13-U'.$_GET['no13']),0,1,"C");

			$this->Ln(7);
			$this->Cell(40,8,iconv('UTF-8','TIS-620','Employee ID : '),1,0,'R');
			$this->Cell(90,8,iconv('UTF-8','TIS-620',''.$_GET['emp_id']),1,0,'C');
			$this->Cell(7,8,iconv('UTF-8','TIS-620',''),0,0,'C');
			$this->Cell(40,8,iconv('UTF-8','TIS-620','Department : '),1,0,'R');
			$this->Cell(90,8,iconv('UTF-8','TIS-620',''.$_GET['departname']),1,1,'C');

			$this->Cell(40,8,iconv('UTF-8','TIS-620','Computer ID : '),1,0,'R');
			$this->Cell(90,8,iconv('UTF-8','TIS-620',''.$_GET['comid']),1,0,'C');
			$this->Cell(7,8,iconv('UTF-8','TIS-620',''),0,0,'C');
			$this->Cell(40,8,iconv('UTF-8','TIS-620','Start Date : '),1,0,'R');
			$this->Cell(90,8,iconv('UTF-8','TIS-620',''.$_GET['startdate']),1,1,'C');

			$this->Cell(40,8,iconv('UTF-8','TIS-620','Name (ENG) : '),1,0,'R');
			$this->Cell(90,8,iconv('UTF-8','TIS-620',''.$_GET['nameEng']),1,0,'C');
			$this->Cell(7,8,iconv('UTF-8','TIS-620',''),0,0,'C');
			$this->Cell(40,8,iconv('UTF-8','TIS-620','Username : '),1,0,'R');
			$this->Cell(90,8,iconv('UTF-8','TIS-620',''.$_GET['username']),1,1,'C');

			$this->Cell(40,8,iconv('UTF-8','TIS-620','Surname (ENG) : '),1,0,'R');
			$this->Cell(90,8,iconv('UTF-8','TIS-620',''.$_GET['surname']),1,0,'C');
			$this->Cell(7,8,iconv('UTF-8','TIS-620',''),0,0,'C');
			$this->Cell(40,8,iconv('UTF-8','TIS-620','Remark : '),1,0,'R');
			$this->Cell(90,8,iconv('UTF-8','TIS-620',''.$_GET['remark']),1,1,'C');

			$this->Ln(10);

			$this->SetFont('browallia','B',14);
			$this->Cell(10,7.5,iconv('UTF-8','TIS-620','Item'),'LTR',0,'C',true);
			$this->Cell(60,7.5,iconv('UTF-8','TIS-620','Description'),'LTR',0,'C',true);
			$this->Cell(30,7.5,iconv('UTF-8','TIS-620','Permission'),'1',0,'C',true);
			$this->Cell(22,7.5,iconv('UTF-8','TIS-620','Owner'),'LTR',0,'C',true);
			$this->Cell(29,7.5,iconv('UTF-8','TIS-620','Cancel'),'1',0,'C',true);
			$this->Cell(29,7.5,iconv('UTF-8','TIS-620','By Requestor'),'1',0,'C',true);
			$this->Cell(29,7.5,iconv('UTF-8','TIS-620','For IT Staff'),'1',0,'C',true);
			$this->Cell(29,7.5,iconv('UTF-8','TIS-620','By Authorized'),'1',0,'C',true);
			$this->Cell(29,7.5,iconv('UTF-8','TIS-620','By Supervisor'),'1',1,'C',true);

			$this->Cell(10,7.5,iconv('UTF-8','TIS-620',''),'LRB',0,'C',true);
			$this->Cell(60,7.5,iconv('UTF-8','TIS-620',''),'LRB',0,'C',true);
			$this->Cell(10,7.5,iconv('UTF-8','TIS-620','R'),'1',0,'C',true);
			$this->Cell(10,7.5,iconv('UTF-8','TIS-620','W'),'1',0,'C',true);
			$this->Cell(10,7.5,iconv('UTF-8','TIS-620','M'),'1',0,'C',true);
			$this->Cell(22,7.5,iconv('UTF-8','TIS-620','Signature'),'LRB',0,'C',true);
			$this->SetFont('browallia','B',11);
			$this->Cell(14.5,7.5,iconv('UTF-8','TIS-620','Signature'),'1',0,'C',true);
			$this->Cell(14.5,7.5,iconv('UTF-8','TIS-620','D/M/Y'),'1',0,'C',true);
			$this->Cell(14.5,7.5,iconv('UTF-8','TIS-620','Signature'),'1',0,'C',true);
			$this->Cell(14.5,7.5,iconv('UTF-8','TIS-620','D/M/Y'),'1',0,'C',true);
			$this->Cell(14.5,7.5,iconv('UTF-8','TIS-620','Signature'),'1',0,'C',true);
			$this->Cell(14.5,7.5,iconv('UTF-8','TIS-620','D/M/Y'),'1',0,'C',true);
			$this->Cell(14.5,7.5,iconv('UTF-8','TIS-620','Signature'),'1',0,'C',true);
			$this->Cell(14.5,7.5,iconv('UTF-8','TIS-620','D/M/Y'),'1',0,'C',true);
			$this->Cell(14.5,7.5,iconv('UTF-8','TIS-620','Signature'),'1',0,'C',true);
			$this->Cell(14.5,7.5,iconv('UTF-8','TIS-620','D/M/Y'),'1',1,'C',true);

		}
	
	function Footer(){

			$this->SetFont('browallia','',16);
			$this->SetY(-15);
			$this->Cell(267,7,iconv('UTF-8','TIS-620','Remark : Standard Drive F: , G: , I: , P: , T: , R: , U: '),1,0,'L');
			}

	function FancyTable($header,$data,$rowdb,$date){
			
			$this->SetFillColor(255,255,255);
			$this->SetTextColor(0);
			$this->SetDrawColor(0,0,0);
			$this->SetLineWidth(.3);
			$this->SetFont('','B');
		//	$this->Text(73,14.5,iconv( 'UTF-8','TIS-620',''.$date),0,1,"C");
		//	$this->Text(200,14.5,iconv( 'UTF-8','TIS-620',''.$rowdb),0,1,"C");
			$w=array(25,55,30,25);
		//	for($i=0;$i<count($header);$i++)
 
		//		$this->Cell($w[$i],4,iconv('UTF-8', 'TIS-620', $header[$i]),1,0,'C',true);
		//	$this->Ln();
			//Color and font restoration
			$this->SetFillColor(255,255,255);
			$this->SetTextColor(0);
			$this->SetFont('angsa','',14);
			//Data
			$fill=false;
			$sum=0;
			$i=1;
			$h=98;
			//$row;

			foreach($data as $row){
			
				if($i > 14){
				
				$this->Cell(10,7,$i,1,0,'C',$fill);
				$this->SetFont('angsa','',10);
				$this->Cell(60,7,$row['per_description'],1,0,'C',$fill);
				$this->SetFont('angsa','',14);
				if($row['per_permission'] == 'r'){
				$this->Cell(10,7,'r',1,0,'C',$fill);
				$this->Image('../images/true.jpg',93,$h,5);
				$this->Cell(10,7,'',1,0,'C',$fill);
				$this->Cell(10,7,'',1,0,'C',$fill);
				}
				if($row['per_permission'] == 'w'){
				$this->Cell(10,7,'',1,0,'C',$fill);
				$this->Cell(10,7,'w',1,0,'C',$fill);
				$this->Image('../images/true.jpg',103,$h,5);
				$this->Cell(10,7,'',1,0,'C',$fill);
				}
				if($row['per_permission'] == 'm'){
				$this->Cell(10,7,'',1,0,'C',$fill);
				$this->Cell(10,7,'',1,0,'C',$fill);
				$this->Cell(10,7,'m',1,0,'C',$fill);
				$this->Image('../images/true.jpg',113,$h,5);
				}
				$this->Cell(22,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Ln();
				$fill=!$fill;
				$i++;
				$h=$h+7;
				if($h > 189){
					$h=98;
				}
			}else{
				
				$this->Cell(10,7,$i,1,0,'C',$fill);
				$this->SetFont('angsa','',10);
				$this->Cell(60,7,$row['per_description'],1,0,'L',$fill);
				$this->SetFont('angsa','',14);
				if($row['per_permission'] == 'r'){
				$this->Cell(10,7,'r',1,0,'C',$fill);
				$this->Image('../images/true.jpg',93,$h,5);
				$this->Cell(10,7,'',1,0,'C',$fill);
				$this->Cell(10,7,'',1,0,'C',$fill);
				}
				if($row['per_permission'] == 'w'){
				$this->Cell(10,7,'',1,0,'C',$fill);
				$this->Cell(10,7,'w',1,0,'C',$fill);
				$this->Image('../images/true.jpg',103,$h,5);
				$this->Cell(10,7,'',1,0,'C',$fill);
				}
				if($row['per_permission'] == 'm'){
				$this->Cell(10,7,'',1,0,'C',$fill);
				$this->Cell(10,7,'',1,0,'C',$fill);
				$this->Cell(10,7,'m',1,0,'C',$fill);
				$this->Image('../images/true.jpg',113,$h,5);
				}
				$this->Cell(22,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Ln();
				$fill=!$fill;
				$i++;
				$h=$h+7;
				if($h > 189){
					$h=98;
				}

			}
						
			}
/*
			for($i=1;$i<=15;$i++)
			{
				$this->Cell(10,7,$i,1,0,'C',$fill);
				$this->Cell(60,7,'',1,0,'C',$fill);
				$this->Cell(10,7,'',1,0,'C',$fill);
				$this->Cell(10,7,'',1,0,'C',$fill);
				$this->Cell(10,7,'',1,0,'C',$fill);
				$this->Cell(22,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
	
				$this->Ln();
				$fill=!$fill;
			}
	*/	
		
	
			}

}
$pdf=new PDF2();
//*** Load MySQL Data ***//
include "../connect.php";
$strSQL = "SELECT * FROM employee INNER JOIN mail ON employee.emp_id = mail.emp_id INNER JOIN depart ON employee.de_id = depart.id INNER JOIN permissionfile ON permissionfile.emp_id = employee.emp_id where employee.emp_id ='$emp_id' order  by per_id asc";
$objQuery = mysql_query($strSQL);
mysql_query("set NAMES'TIS620'");
$resultData = array();
for ($i=0;$i<mysql_num_rows($objQuery);$i++) {
	$result = mysql_fetch_array($objQuery);
	$result['per_description'] = iconv("UTF-8", "ISO-8859-11",$result['per_description']);
	array_push($resultData,$result);

	if($result['mail_authorizedDate'] == "0000-00-00 00:00:00"){
		$result['mail_authorizedDate'] = "";
	}
	if($result['mail_requestUserDate'] == "0000-00-00 00:00:00"){
		$result['mail_requestUserDate'] = "";
	}
	if($result['mail_staffITdate'] == "0000-00-00 00:00:00"){
		$result['mail_staffITdate'] = "";
	}
	if($result['mail_authorizedConDate'] == "0000-00-00 00:00:00"){
		$result['mail_authorizedConDate'] = "";
	}
	if($result['mail_supervisorDate'] == "0000-00-00 00:00:00"){
		$result['mail_supervisorDate'] = "";
	}
}
//************************//
$pdf->AddPage('L','A4');
$pdf->SetLeftMargin( 20 );
//$pdf->SetAutoPageBreak(true , 5);
$pdf->SetAutoPageBreak(true,10);
$pdf->AddFont('browallia','','browa.php');
$pdf->AddFont('browallia','B','browab.php');
$pdf->AddFont('browallia','I','browai.php');
$pdf->AddFont('browallia','BI','browaz.php');
$pdf->SetFont('browallia','B',16);
$pdf->SetFillColor(194,194,194);
//$date=$result['per_createDate'];

$pdf->FancyTable($header,$resultData,$i,$date);

$pdfs2="../Bill_Cancel_F-IT-004/"."F-IT-004-".$emp_id.".pdf"; 
$pdf->Output($pdfs2,"F");


	require_once('../sendmail/class.phpmailer.php');

	$mail = new PHPMailer();
	$mail->CharSet = "utf-8";
	$mail->IsHTML(true);
	$mail->IsSMTP();
	$mail->SMTPAuth = true; 
	$mail->SMTPSecure = ""; 
	$mail->Host = "192.168.10.180"; 
	$mail->Port = 25; 
	$mail->Username = "itservice@admail.local"; 
	$mail->Password = "adinop1*"; 
	$mail->From = "itservice@admail.local";
	//$mail->AddReplyTo = "support@thaicreate.com"; // Reply
	$mail->FromName = "System IT";  
	$mail->Subject = "ยกเลิกสิทธิ์ ของคุณ ".$result['emp_nameTh']." ".$result['emp_surnameTh']." (CANCEL F-IT-009 , F-IT-004)"; 
	$mail->Body = "เนื่องจากคุณ " .$result['emp_nameTh']." ".$result['emp_surnameTh']." ได้ลาออกจากบริษัทแล้ว อนุมัติโดย ".$f_name." ".$l_name;
	
	$mail->AddAddress("Auttavut@admail.local", "Mr. Auttavut");
	$mail->AddAddress("suchart@admail.local", "P' Chart");
	//$mail->AddAddress("suchart@admail.local", "Mr.Suchart"); 
	$mail->AddAttachment($pdfs);
	$mail->AddAttachment($pdfs2);
	
	//$mail->AddCC("nathanon@admail.local", "P' Pae");
	//$mail->AddCC("priowchaiit@admail.local", "P' Ning");
	//$mail->AddCC("suchart@admail.local", "P' Chart");
	
	//$mail->set('X-Priority', '1'); //Priority 1 = High, 3 = Normal, 5 = low
	
	if(!$mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
	} else {
		//echo "Message sent!";
		echo "<script>window.location='report_cancel.php?id_emp=$emp_id';</script>";
	}
	
	
	mysql_close($connection);
?>
</body>
</html>